package com.atguigu.gulimall.gateway.controller;

import com.atguigu.common.utils.MyColor;
import com.atguigu.gulimall.gateway.myuntil.AESUtil;
import com.atguigu.gulimall.gateway.myuntil.AESUtil1;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @NAME: LogDing
 * @USER: wjj
 * @DATE: 2023/11/27
 * @TIME: 15:50
 * @DAY_NAME_FULL: 星期一
 * @PROJECT_NAME: boot-01-helloworld
 */
@RestController
public class LogDing {
//    private Long aa=259197935521114770L;
    public static void main(String[] args) throws Exception {
        String s = DigestUtils.md5Hex("lbNTQ5Prug7g1EPBe8bavp3CUGJCuBZr");
        System.out.println(s);
        String encrypt = AESUtil1.decrypt("lbNTQ5Prug7g1EPBe8bavp3CUGJCuBZr", s.substring(0, 16), "SmfqFMFrQZNAE8PiQLhinFuIHoNG5VAP8elryCHHtBMvOrptUNjD8b0nJnOW7b7y0FprXvagUZIVw7UeqGuMUKq+rOA0NzLlQO0tO1/djtA=");
        System.out.println(encrypt);
    }

    @RequestMapping("/log")
    @ResponseBody
    public String test_log(@RequestBody Map<String,String> log, String app_secret) throws Exception {
        String s = DigestUtils.md5Hex(app_secret);
        String success = AESUtil1.encrypt(app_secret, s.substring(0,16), "success");
        String rLog="{\"encrypt\":\""+success+"\"}";
        MyColor.println("返回数据："+rLog);
//        MyColor.println("+++++："+log);
        String encrypt = AESUtil1.decrypt(app_secret, s.substring(0, 16), log.get("encrypt"));
        MyColor.println("事件订阅信息：\n"+encrypt);
        return rLog;
    }
}
